//
//  LoginAuthCodeView.swift
//  LeTu
//
//  Created by g1 on 2023/12/4.
//

import UIKit

class LoginAuthCodeView: UIView {

    init(placeholder: String, target: Any, action: Selector) {
        super.init(frame: .zero)
        
        configUI()
        contentTextField.placeholder = placeholder
        
        getAuthCodeBtn.addTarget(target, action: action)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        DispatchQueue.main.async {
            self.backView.layerCornerRadius(self.backView.height)
        }
    }
    
    // MARK: - configUI
    func configUI() {
        
        addSubview(backView)
        backView.addSubview(getAuthCodeBtn)
        backView.addSubview(contentTextField)
        
        backView.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.top.equalToSuperview()
        }
        getAuthCodeBtn.snp.makeConstraints { make in
            make.width.equalTo(LanguageManager.shared.currentLanguage == .zh ? 110:158)
            make.right.top.bottom.equalToSuperview()
        }
        contentTextField.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(getAuthCodeBtn.snp.left)
            make.top.bottom.equalToSuperview()
        }
        
    }
    private lazy var backView: UIView = {
        let backView = UIView()
        backView.backgroundColor = .app_inputViewBackColor
        return backView
    }()
    private(set) lazy var getAuthCodeBtn: CustomClickableView = {
        let getAuthCodeBtn = CustomClickableView()
        getAuthCodeBtn.setTitle("获取验证码".localized)
        getAuthCodeBtn.setTitleColor(.app_textLightBlueColor)
        getAuthCodeBtn.setFont(kSetPingFangRegular(14))
        return getAuthCodeBtn
    }()
    private(set) lazy var contentTextField: UITextField = {
        let contentTextField = UITextField()
        contentTextField.font = kSetPingFangMedium(14)
        contentTextField.textColor = .app_textDarkGrayColor
        contentTextField.keyboardType = .numberPad
        return contentTextField
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
